﻿@{
    ViewBag.Title = "函数列表";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script type="text/javascript">
        var doActionOptions = "<select onchange='return DoAction(this.options.selectedIndex,this.value)' ><option value=''>-请选择-</option>";
        $(function () {
            btnSearch_Click();
            $.post("/SystemConfiguration/BindDropwown/?keyName=ActionType", function (result) {
                var arr_sel = new Array();
                if (result != "") {
                    for (var i = 0; i < result.length; i++) {
                        arr_sel.push("<option value='");
                        arr_sel.push(result[i].Value);
                        arr_sel.push("'>");
                        arr_sel.push(result[i].Name);
                        arr_sel.push("</option>");
                    }
                    $("#ActionType").append(arr_sel.join("")); 
                }
            });
        });
        var opts = {
            rows: 10,
            height: 450,
            url: "/Function/GetList",
            para: {},
            idField: "Guid",
            checkbox: false,
            columns: [
                    { field: 'FunName', title: '函数名称', width: 30, sortable: true },
                    { field: 'ParamCount', title: '参数数量', align: 'center', width: 10, sortable: true },
                    { field: 'FunType', title: '函数类型', align: 'center', width: 10, sortable: true,
                        formatter: function (value, rowData, rowIndex) {
                            var format = "";
                            switch (value) {
                                case 1:
                                    return "表值函数";
                                    break;
                                case 2:
                                    return "标量值函数";
                                    break;
                                case 3:
                                    return "聚合函数";
                                    break;
                                case 4:
                                    return "系统函数";
                                    break;
                            }
                        }
                    },
                    { field: 'ActionType', title: '功能类型', align: 'center', width: 10, sortable: true },
                    { field: 'Description', title: '函数说明', width: 30, sortable: true },
                    { field: 'Guid', title: '操作', align: 'center', width: 10,
                        formatter: function (value, rowData, rowIndex) {
                            var format = doActionOptions;
                            format += "<option value='" + value + "'>修改</option>"
                            format += "<option value=\"" + value + "\">删除</option>"
                            format += "</select>";
                            return format;
                        }
                    }
                    ]
        };

        function btnAdd_Click() {
            AddFun();
        }
        function btnSearch_Click(p) {
            opts.para["funName"] = $.trim($("#txtFunName").val());
            opts.para["funType"] = $.trim($("#ddlFunType").val());
            opts.para["actionType"] = $.trim($("#ActionType").val());
            if (p == 1)
                thisPageNum = 1;
            $("#DataGrid").dg(opts);
        } 
        //“操作”下拉框事件
        function DoAction(i, value) {
            if (i == 1) { 
                EditFun(value); // 编辑
            }
            else if (i == 2) { 
                DeleteFun(value);// 删除
            }
        }

        function AddFun() { 
            var url = "/Function/Edit";
            showModalMany('TaskStatus', url, '600', '365' );
            btnSearch_Click();
        }

        function EditFun(funID) { 
            var url = "/Function/Edit?funID=" + funID;
            showModalMany('TaskStatus', url, '600', '365' );
            btnSearch_Click();
        }
        function DeleteFun(funID) {
            if (confirm("确定要删除吗?")) {
                $.post("/Function/Delete?funID=" + funID, function (res) {
                    if (res==1) {
                        alert("删除成功！");
                    }
                    else {
                        alert(res);
                    }
                    btnSearch_Click();
                });
            } else
                btnSearch_Click();
        }
    </script>
}
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/search.png" />
            </td>
            <td width="300">
                函数搜索
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td>
                函数名称：
                <input id="txtFunName" type="text" class="inputSearch" style="width: 120px;" />
                函数类型：
                <select id="ddlFunType" style="width: 130px;">
                    <option value="0">-全部-</option>
                    <option value="1">表值函数</option>
                    <option value="2">标量值函数</option>
                    <option value="3">聚合函数</option>
                    <option value="4">系统函数</option>
                </select>
                功能类型：
                <select id="ActionType" style="width: 130px;">
                    <option value="">-全部-</option> 
                </select>
                <input id="btnSearch" type="button" class="button" value=" 搜 索 " onclick="btnSearch_Click(1)" />
            </td>
        </tr>
    </table>
    @{
        // 渲染输出列表
        var dataGrid = new ViewDataDictionary();
        dataGrid.Add("PanelTitle", "函数列表");
        dataGrid.Add("GridID", "DataGrid");
        dataGrid.Add("ShowAddButton", true);
        dataGrid.Add("ShowDeleteButton", false);
        dataGrid.Add("ShowOtherButton", false);
        dataGrid.Add("OtherButtonID", "btnView");
        dataGrid.Add("OtherButtonValue", "查 看");
        dataGrid.Add("OtherButtonClick", "btnView_Click()");
        dataGrid.Add("ShowBackButton", false);
        dataGrid.Add("ShowCloseButton", false);
        dataGrid.Add("ShowPager", true);
        dataGrid.Add("ShowLoading", true);
        @Html.Partial("_GridPanel", dataGrid);
    }
</div>
